
package flc.ast.dialog;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.lxj.xpopup.core.AttachPopupView;

import flc.ast.R;

public class SortDialog extends AttachPopupView implements View.OnClickListener {


    public SortDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_sort;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        initView();
    }

    protected void initView() {
        findViewById(R.id.tvDefault).setOnClickListener(this);
        findViewById(R.id.tvName).setOnClickListener(this);
        findViewById(R.id.tvTime).setOnClickListener(this);
        findViewById(R.id.tvSize).setOnClickListener(this);
        findViewById(R.id.tvType).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tvDefault) {
            dismiss();
            if (listener != null) {
                listener.click(0, getContext().getString(R.string.default_sorting));
            }
        } else if (id == R.id.tvName) {
            dismiss();
            if (listener != null) {
                listener.click(1, getContext().getString(R.string.by_name));
            }
        } else if (id == R.id.tvTime) {
            dismiss();
            if (listener != null) {
                listener.click(2, getContext().getString(R.string.by_time));
            }
        } else if (id == R.id.tvSize) {
            dismiss();
            if (listener != null) {
                listener.click(3, getContext().getString(R.string.by_file_size));
            }
        } else if (id == R.id.tvType) {
            dismiss();
            if (listener != null) {
                listener.click(4, getContext().getString(R.string.by_type));
            }
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void click(int position, String name);
    }

}
